
/********订单列表，订单详情**********/

var OrderList = {};

//跳转至订单详情页面
OrderList.toDetails = function(orderId){
	window.location.href = "#/order_details?id="+ orderId;
};

//Demo页显示隐藏
OrderList.showType = function(type){
	$("#type"+ type).show();
};

//弹框隐藏
OrderList.closedBox =  function (){
	$(".modal-dialog-box").hide();
};

//显示 - 中止订单弹框
OrderList.suspendDialog =  function (orderId,type){
	$("#order_id").val(orderId);
	$("#order_Type").val(type);
	
	$("#suspendDialog").show();
};

//显示 - 取消订单弹框
OrderList.cancelDialog =  function (orderId,type){
	$("#order_id").val(orderId);
	$("#order_Type").val(type);
	
	$("#cancelDialog").show();
};

/**
 * 获取列表
 */
OrderList.orderList =  function(){
	
	//获取筛选调减
	 var status;
	 $(".menubox .butbox a").each(function() {
		 if($(this).hasClass("active")){
			 status = $(this).attr("vals");
		 }
	 });

	
	var param = {
	  url:'shop/order',
	  ajaxType:'GET',
	  status : status,
	  isObject:true
    }
	
	//loading
	$(".nulldate").hide();
	// $("#orderList_content").empty().append("<div class='loaddiv'><img src='images/loginload.gif'>&nbsp;&nbsp;&nbsp;数据加载中......</div>");

	doInvoke(param,function(data){
		if(data.code == code10000){
			if(!isEmptyObject(data.data.list)){
			   $("#orderList_content").empty().append($("#orderList_Template").render(data.data.list));
			}else{
				$("#orderList_content").empty();
			    $(".nulldate").show();
			}
		}else{
		   //errorAlert(data.message);
		}
	});
}

/**
 * 获取详情
 */
OrderList.getOrder = function(orderId){

	var param = {
		  url:'shop/order/' + orderId,
		  ajaxType:'GET'
	}
	
	//loading
	//$("#orderType_Content").empty().append("<div class='loaddiv2'><img src='images/loginload.gif'>&nbsp;&nbsp;&nbsp;数据加载中......</div>");

	doInvoke(param,function(data){
		if(data.code == code10000){
			var orderObj = data.data.order;
			
			 //set详情头部信息
			 $("#orderHeard_Content").empty().append($("#orderHeard_Template").render(orderObj));
			 //set 专属客户经理
			 if(orderObj.waiterName != null && orderObj.waiterPhone  != null){
				 $(".det-contactBox").show();
				 $(".det-contact-main").empty().append($("#contact_Template").render(orderObj));
			 }else{
				 $(".det-contactBox").hide();
			 }
			 
			 //set封装类型
			 $("#orderType_Content").empty().append($("#orderType_Template").render(orderObj));
			 //set详情信息
			 $("#orderDetails_Content").empty().append($("#orderDetails_Template").render(data.data));
			 
			 //初始化wafer Tab选卡
			 $('.wafer-tab li').click(function(){
				var index = $(this).index();
				$('.wafer-tab li').removeClass('active');
				$(this).addClass('active');
				$('.wafer-tab-info li').eq(index).show().siblings().hide();
				$('.wafer-file').addClass('hidden');
    		$('.wafer-file').eq(index).removeClass('hidden');
			 });
			 
			 //判断是否显示支付模块
			 if(orderObj.status == 2){
				 $(".order-foot").show();
				 //加载支付模块
				 $("#orderPay_Content").empty().append($("#orderPay_Template").render(orderObj));
			 }
		}else{
		   errorAlert(data.message);
		}
	});
};


//根据文件后缀判断文件类型的图标
$.views.helpers({
	'getFileType':function(fileName){
		//PDF，DWG，DXF，RAR/ZIP，Word，Excel
		if(fileName == null){
			fileName="default";
		}
		var fileVal = fileName.toLowerCase();
		if(fileVal.indexOf('pdf') > -1){
			return "icon-pdf.png";
		}else if(fileVal.indexOf('dwg') > -1){
			return "icon-dwg.png";
		}else if(fileVal.indexOf('dxf') > -1){
			return "icon-dxf.png";
		}else if(fileVal.indexOf('rar') > -1){
			return "icon-rar.png";
		}else if(fileVal.indexOf('zip') > -1){
			return "icon-zip.png";
		}else if(fileVal.indexOf('doc') > -1){
			return "icon-doc.png";
		}else if(fileVal.indexOf('xls') > -1){
			return "icon-xls.png";
		}else if(fileVal.indexOf('jpg') > -1){
			return "icon-jpg.png";
		}else{
			return "icon-pdf.png";
		}
	}
});


/**
 * 取消订单
 * orderId 订单ID
 * type 0列表入口  1 详情入口
 */
OrderList.cancel = function(){
	var orderId = $("#order_id").val();
	var type = $("#order_Type").val();
	
	var param = {
		  url:'shop/order/'+ orderId +'/cancel',
		  ajaxType:'PUT'
	}
	doInvoke(param,function(data){
		
		if(data.code == code10000){
			$("#cancelDialog").show();  //隐藏弹框
			loboxSucAlert("订单取消成功！");
			$("#cancelDialog").hide(); //隐藏弹框
			if(type == 0){
				OrderList.orderList();
			}else if(type == 1){
				window.location.href='#/order_list';    //跳转入订单列表
			}
		}else{
		   errorAlert(data.message);
		}
	});
};

/**
 * 中止订单
 * orderId 订单ID
 * type 0列表入口  1 详情入口
 */
OrderList.stop = function(){
	var orderId = $("#order_id").val();
	var type = $("#order_Type").val();
	
	var param = {
		  url:'shop/order/'+ orderId +'/stop',
		  ajaxType:'PUT'
	}
	doInvoke(param,function(data){
		if(data.code == code10000){
			$("#suspendDialog").show(); //隐藏弹框
			loboxSucAlert("此订单已中止！");
			if(type == 0){
				OrderList.orderList();
			}else if(type == 1){
				window.location.href='#/order_list';    //跳转入订单列表
			}
		}else{
		   errorAlert(data.message);
		}
	});
};


/**
 * 订单支付
 * orderId 订单ID
 * type 0列表入口  1 详情入口
 */
OrderList.payPrder = function(code){
    /*
	var param = {
		  url:'shop/order/'+ orderId +'/order',
		  ajaxType:'PUT'
	}
	doInvoke(param,function(data){
		if(data.code == code10000){
			window.location.href='#/pay_preview?id=' + orderId;    //跳转入订单支付
		}else{
		   errorAlert(data.message);
		}
	});*/
	
	window.location.href='#/pay_preview?id=' + code; 
};

OrderList.orderAdd = function() {
	$('#firstDialog').hide();
	window.location.href='#/order_add';
};

